﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Globalization;

namespace BurnSystems.Gpx
{
    /// <summary>
    /// rte represents route - an ordered list of waypoints representing a series 
    /// of turn points leading to a destination. 
    /// </summary>
    public class GpxRoute : GpxNamedElement
    {
        /// <summary>
        /// Initializes a new instance of the GpxTrack class.
        /// </summary>
        /// <param name="node">Node to be used for track</param>
        public GpxRoute(XElement node)
            : base(node)
        {
        }

        /// <summary>
        /// Gets or sets the number
        /// </summary>
        public long Number
        {
            get
            {
                return Convert.ToInt32(this.node.GetElementContent("number", "0"));
            }

            set
            {
                this.node.SetElementContent("number", value.ToString(CultureInfo.InvariantCulture));
            }
        }

        /// <summary>
        /// Gets or sets the Type
        /// </summary>
        public string Type
        {
            get
            {
                return this.node.GetElementContent("type", string.Empty);
            }

            set
            {
                this.node.SetElementContent("type", value);
            }
        }

        /// <summary>
        /// Gets a list of waypoints
        /// </summary>
        public IList<GpxWaypoint> Waypoints
        {
            get
            {
                return this.node
                    .Elements(GpxDocument.FullyQualifiedNS + "rtept")
                    .Select(x => new GpxWaypoint(x))
                    .ToList()
                    .AsReadOnly();
            }
        }
    }
}
